home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 445_01 / alert10 / alert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-04  |  3.9 KB  |  180 lines

  1. /*************************************************************************/
  2. /*                               ALERT Source                            */
  3. /*                                                                       */
  4. /*                                 M\Cooper                              */
  5. /*                          3425 Chestnut Ridge Rd.                      */
  6. /*                        Grantsville, MD 21536-9801                     */
  7. /*************************************************************************/
  8.  
  9.  
  10. #include <graphics.h>
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <dos.h>
  14. #include <time.h>
  15. #include <stdlib.h>
  16. #include "alert.h"
  17.  
  18.  
  19.  
  20. void main( int argc, char **argv )
  21. {
  22.  
  23.    
  24.    time_t starting_time;
  25.  
  26.    clock_t t_start,
  27.        t_end,
  28.        t_tot,
  29.        hrs,
  30.        min,
  31.        sec;
  32.  
  33.       SoundFlag = ON;
  34.  
  35.       if( argc > 1 )
  36.      if( *argv[1] == 's' )
  37.          SoundFlag = OFF;
  38.  
  39.  
  40.       t_start = clock() / CLK_TCK;
  41.       starting_time = time( NULL );
  42.  
  43.       graphics_setup( SETUP_COLOR );
  44.  
  45.       while( !( kbhit() && getch() == EXITVALUE ) )  // Press EXITVALUE (in alert.h file) to exit.
  46.      FlashCycle();
  47.  
  48.       closegraph();
  49.  
  50.       t_end = clock() / CLK_TCK;
  51.  
  52.       t_tot = t_end- t_start;
  53.       hrs = t_tot / 3600L;
  54.       t_tot = t_tot - ( hrs * 3600L );
  55.       min = t_tot / 60L;
  56.       t_tot = t_tot - ( min * 60L );
  57.       sec = t_tot;
  58.  
  59.       textcolor( LIGHTRED );
  60.       cprintf( "\nALERT has been active since " );
  61.       cprintf( ctime( &starting_time ) ); 
  62.  
  63.       textcolor( LIGHTBLUE );
  64.       cprintf( "                            " );
  65.       cprintf( "ALERT has been running for " );
  66.  
  67.       if( hrs )
  68.      if( hrs > 1 )
  69.         cprintf( "%ld hours, ",  hrs );
  70.      else
  71.         cprintf( "%ld hour, ", hrs );
  72.  
  73.       if( min )
  74.      if( min > 1 )
  75.         cprintf( "%ld minutes, ", min );
  76.      else
  77.         cprintf( "%ld minute, ", min );
  78.         
  79.       if( sec )
  80.      if( sec > 1 )
  81.         cprintf( "%ld seconds.\n\n\n", sec );
  82.      else
  83.         cprintf( "%ld second.\n\n\n", sec );
  84.             
  85.  
  86. }
  87.  
  88.  
  89. /*************************************************************************/
  90. /*                    GENERIC VGA GRAPHICS SETUP                         */
  91. /*************************************************************************/
  92.  
  93. void graphics_setup( int background_color )
  94. {
  95.    int grdriver = VGA,
  96.        grmode = VGAHI;
  97.  
  98.        registerfarbgidriver( EGAVGA_driver_far );
  99.        registerfarbgifont( triplex_font_far );
  100.        initgraph( &grdriver, &grmode, "" );
  101.  
  102.        if( graphresult() )  //Error in opening graphics mode..
  103.           {
  104.           closegraph();
  105.           exit ( GR_ERROR );
  106.           puts( "Error in opening graphics systems!" );
  107.           }
  108.  
  109.        setbkcolor( background_color );
  110.        setcolor( PIXEL_COLOR );
  111.  
  112.        return;
  113.  
  114. }
  115.  
  116. void write_text( int x_coord, int y_coord, int type_size, char* text )
  117. {
  118.       settextstyle( TRIPLEX_FONT, HORIZ_DIR, type_size);
  119.       outtextxy( x_coord, y_coord, text );
  120.  
  121.       return;
  122. }
  123.  
  124. void FlashCycle()
  125. {
  126.  
  127.     static char *txt1,
  128.         *txt2;
  129.    int y_ht,
  130.        line1color,
  131.        count = -1;
  132.  
  133.       randomize();
  134.  
  135.       txt1 = Msg1;
  136.       txt2 = Msg2;
  137.  
  138.       switch ( random ( RANDOM + 1 ) )
  139.      {
  140.      case 0:
  141.         setbkcolor( LIGHTBLUE );
  142.         line1color = YELLOW;
  143.         break;
  144.      case 1:
  145.         setbkcolor( WHITE );
  146.         line1color = DARKGRAY;
  147.         break;
  148.      case 2:
  149.         setbkcolor( LIGHTGREEN );
  150.         line1color = BLUE;
  151.         break;
  152.      default:
  153.         setbkcolor( YELLOW );
  154.         line1color = RED;
  155.       }
  156.  
  157.       y_ht = random( MAXYHT );
  158.       WRITE_LINE1;
  159.  
  160.       while( !kbhit() && ++count < MAXCYCLECOUNT )
  161.      {
  162.      delay( DELAY ); 
  163.      ERASE_LINE1;
  164.      WRITE_LINE2;
  165.  
  166.      if( random( MAXCYCLECOUNT ) >= DIALPHONE && SoundFlag == ON )
  167.         if( !random( RANDOM ) )
  168.            warble();
  169.         else
  170.            dial();
  171.  
  172.      delay( DELAY );           
  173.      ERASE_LINE2;
  174.      WRITE_LINE1; 
  175.      }
  176.       cleardevice();
  177.  
  178.       return;
  179. }
  180.